What is 7zip-bin?
The 7zip-bin npm package provides a way to use the 7-Zip compression tool within Node.js applications. It includes precompiled binaries for various platforms, allowing you to perform compression and decompression tasks without needing to install 7-Zip separately.
What are 7zip-bin's main functionalities?
Compress files
This feature allows you to compress files into a 7z archive. The code sample demonstrates how to use the 7zip-bin package to compress 'file.txt' into 'archive.7z'.
const { execFile } = require('child_process');
const pathTo7zip = require('7zip-bin').path7za;
execFile(pathTo7zip, ['a', 'archive.7z', 'file.txt'], (err, stdout, stderr) => {
if (err) throw err;
console.log(stdout);
});
Decompress files
This feature allows you to decompress files from a 7z archive. The code sample demonstrates how to use the 7zip-bin package to extract 'archive.7z'.
const { execFile } = require('child_process');
const pathTo7zip = require('7zip-bin').path7za;
execFile(pathTo7zip, ['x', 'archive.7z'], (err, stdout, stderr) => {
if (err) throw err;
console.log(stdout);
});
List contents of an archive
This feature allows you to list the contents of a 7z archive. The code sample demonstrates how to use the 7zip-bin package to list the contents of 'archive.7z'.
const { execFile } = require('child_process');
const pathTo7zip = require('7zip-bin').path7za;
execFile(pathTo7zip, ['l', 'archive.7z'], (err, stdout, stderr) => {
if (err) throw err;
console.log(stdout);
});
Other packages similar to 7zip-bin
node-7z
The node-7z package provides a similar interface for working with 7-Zip in Node.js. It offers more advanced features like progress tracking and event-based notifications. However, it requires 7-Zip to be installed separately on the system.
decompress
The decompress package is a general-purpose decompression library for Node.js. It supports multiple formats including .zip, .tar, .tar.gz, and .tar.bz2. Unlike 7zip-bin, it does not support the 7z format but is useful for handling other common archive types.
adm-zip
The adm-zip package is a pure JavaScript implementation for handling .zip files. It does not require any external binaries and is easy to use for basic zip file operations. However, it does not support the 7z format.